package com.intellagric.controller.module.trace_process;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.traceability.ProcessTemplateVo;
import com.intellagric.pojo.TraceProcessTemplate;
import com.intellagric.service.traceability.trace_process.ProcessTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2019/1/13
 * @DESC： 生产流程模板管理
 */
@Controller
public class ProcessTemplateController {

    @Autowired
    private ProcessTemplateService processTemplateService;

    /**
     * 添加生产流程模板信息
     * @Param processTemplate
     * @return ResponseMessage
     */
    @RequestMapping("/process/template/add")
    @ResponseBody
    public ResponseMessage add(TraceProcessTemplate processTemplate) {
        processTemplate.setId(UUID.randomUUID().toString().replaceAll("-",""));
        processTemplate.setCreateDate(new Date());
        processTemplate.setUpdateDate(new Date());
        return processTemplateService.addProcessTemplate(processTemplate);
    }

    /**
     * 删除生产流程模板信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/process/template/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return processTemplateService.deleteProcessTemplate(id);
    }

    /**
     * 修改生产流程模板信息
     * @Param processTemplate
     * @return ResponseMessage
     */
    @RequestMapping("/process/template/edit")
    @ResponseBody
    public ResponseMessage edit(TraceProcessTemplate processTemplate) {
        processTemplate.setUpdateDate(new Date());
        return processTemplateService.editProcessTemplate(processTemplate);
    }

    /**
     * 查询生产流程模板信息
     * @return TraceProcessTemplate
     */
    @RequestMapping("/process/template/{id}")
    @ResponseBody
    public TraceProcessTemplate get(@PathVariable String id) {
        return processTemplateService.getProcessTemplateById(id);
    }

    /**
     * 查询生产流程模板信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/process/template/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return processTemplateService.getProcessTemplateList();
    }

    /**
     * 分页查询生产流程模板信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/process/template/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return processTemplateService.getProcessTemplatePage(page,limit);
    }

    /**
     * 多条件分页查询生产流程模板信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/process/template/query")
    @ResponseBody
    public LayuiDataGridResult getPageByVo(int page,int limit,ProcessTemplateVo processTemplateVo) {
        return processTemplateService.getProcessTemplateByVo(page,limit,processTemplateVo);
    }

}
